﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace ObjectManager
{
    public class DangNhap : ManagerComponent
    {
        public DangNhapDTO ThongTin { get; set; }

        private DangNhapDAO DangNhapDAO { get; set; }

        private void Initialize()
        {
            ThongTin = new DangNhapDTO();
            DangNhapDAO = new DangNhapDAO();
        }

        public DangNhap()
        {
            Initialize();
        }

        public override int Add()
        {
            DangNhapDAO.DangNhapDTO = ThongTin;
            return DangNhapDAO.Insert();
        }

        public override int Update()
        {
            DangNhapDAO.DangNhapDTO = ThongTin;
            return DangNhapDAO.Update();
        }

        public int UpdatePassword()
        {
            DangNhapDAO.DangNhapDTO = ThongTin;
            return DangNhapDAO.UpdatePassword();
        }

        public int UpdatePassword(string MatKhau)
        {
            DangNhapDAO.DangNhapDTO = ThongTin;
            return DangNhapDAO.UpdatePassword(MatKhau);
        }

        public int ChangePassword(string Old_Password, string New_Password)
        {
            DangNhapDAO.DangNhapDTO = ThongTin;
            return DangNhapDAO.ChangePassword(Old_Password, New_Password);
        }

        public override int Remove()
        {
            DangNhapDAO.DangNhapDTO = ThongTin;
            return DangNhapDAO.Delete();
        }

        public bool Check()
        {
            DangNhapDAO.DangNhapDTO = ThongTin;
            bool check = DangNhapDAO.Check();
            if (check)
            {
                ThongTin = DangNhapDAO.DangNhapDTO;
            }
            return check;
        }

        public DataTable ListAll()
        {
            return DangNhapDAO.ListAll();
        }

        public DataTable ListAll(string TenDangNhap, string Ten, string Quyen)
        {
            if (string.IsNullOrEmpty(TenDangNhap))
            {
                TenDangNhap = "%";
            }
            else
            {
                TenDangNhap = "%" + TenDangNhap + "%";
            }
            if (string.IsNullOrEmpty(Ten))
            {
                Ten = "%";
            }
            else
            {
                Ten = "%" + Ten + "%";
            }
            if (string.IsNullOrEmpty(Quyen))
            {
                Quyen = "%";
            }
            else
            {
                Quyen = "%" + Quyen + "%";
            }
            return DangNhapDAO.ListAll(TenDangNhap, Ten, Quyen);
        }

        public string[] ListName()
        {
            return DangNhapDAO.ListName();
        }
    }
}
